#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2018/4/18 17:53
# @Author  : yangdy
# @Email   : yangdy@egu360.com
# @File    : 无重复字符的最长子串.py
# @Software: PyCharm

"""  
无重复字符的最长子串
TODO模块说明
Public Class:
-	TODO类名: TODO类说明 
Public Methods: 
-	TODO方法名: TODO方法说明
"""


class Solution:

    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        print(s)
        m = {}
        last = -1
        l = len(s)
        ans = 0
        for i in range(l):
            print('i=%d:%s' % (i, s[i]))
            print('last=%d'%last)
            print(m)
            print(m.get(s[i]))
            if m.get(s[i])==None:
                m[s[i]] = i
                ans = i - last if i - last > ans else ans
            else:
                if m[s[i]] > last:
                    k = i - m[s[i]]
                else:
                    k = i - last
                ans = k if k > ans else ans
                last = m[s[i]]
                m[s[i]] = i
            print('ans=%d'%ans)
        return ans


# s = "abcabcbb"
s = "ggububgvfk"
solution = Solution()
print(solution.lengthOfLongestSubstring(s))
